home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4259 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: ntc.nokia.com!usenet
  2. From: Risto Lankinen <risto.lankinen@ntc.nokia.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: 29 Jan 1996 09:31:43 GMT
  6. Organization: Nokia Telecommunications
  7. Message-ID: <4ei45v$mci@axl02it.ntc.nokia.com>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com> <4dpcfo$293@clarknet.clark.net> <hamilton-2401960104020001@dialup-86.austin.io.com> <3108c867.40236096@nntp.ix.netcom.com> <4eb6kq$ksf@gazette.tandem.com> <31098f8f.11689344@nntp.ix.netcom.com>
  9. NNTP-Posting-Host: pc-rlankinen.ntc.nokia.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15. Hi!
  16.  
  17. miker3@ix.netcom.com (Mike Rubenstein) wrote:
  18. >yun_yeogirl <yyg> wrote:
  19. >
  20. >> Michael M Rubenstein wrote :
  21. >> 
  22. >>         [Example:
  23. >>           i = v[i++];      // the behavior is undefined
  24. >> 
  25. >>           i = ++i + 1;     // the behavior is undefined
  26. >> 
  27.    [etc...]
  28.  
  29. Isn't the mere existence of this discussion an adequate reason for
  30. reconsidering the standard when it comes to the evaluation order of
  31. such expressions?  What I mean is, why does the standard *need* to
  32. specify that something is 'undefined' when they could be 'defined'
  33. anyway.  This would have the added bonus that no existing programs
  34. conforming to the standard won't break simply because they were not
  35. allowed to make assumptions about undefined behaviour, whereas the
  36. new programs would have the added power of expression without fear
  37. of the compilers misinterpreting the intent.
  38.  
  39. For example, instead of...
  40.  
  41. >>           i = ++i + 1;     // the behavior is undefined
  42.  
  43. .. one could define in the standard...
  44.  
  45. >>           i = ++i + 1;     // operator+() evaluates and executes
  46. >>                            // its arguments in the order of their
  47. >>                            // associativity, ie. '++i' first, the
  48. >>                            // constant expression '1' next, and
  49. >>                            // the operator+() last.  Finally, the
  50. >>                            // result is assigned to 'i'.  Thus the
  51. >>                            // example equals to 'i = i + 2'.
  52.  
  53. .. and within one version cycle all compilers will behave same.
  54.  
  55. Or, for curiosity's sake, why not?
  56.  
  57. terv: Risto L.
  58.  
  59. -- 
  60. Risto Lankinen / System Engineer  ***************************************
  61. Nokia Telecommunications,         *  2                              2   *
  62. Cellular Data; Helsinki, Finland. * 2 -1 is PRIME!  Now working on 2 +1 *
  63. risto.lankinen@ntc.nokia.com      ***************************************
  64.  
  65.  
  66.